<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0">
    <title>垂直导航栏</title>
    <!-- 引入Bootstrap CSS文件 -->
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/bootstrap-5.3.0-alpha1-dist/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/assets/js/jquery-3.7.1.min.js"></script>
    <!-- 自定义CSS样式 -->
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/assets/css/reset.css">
    <style>
        body {
            overflow: hidden;
        }
    </style>

    <script>
        function loginIn() {
            var username = $("#exampleInputEmail1").val();
            var password = $("#exampleInputPassword1").val();
            var role = $("#role").val();
            let formData = new FormData();
            formData.append("userName", username);
            formData.append("password", password);
            formData.append("role", role);
            $.ajax({
                url: "${pageContext.request.contextPath}/selectAllUser",
                headers: {
                    "Cache-Control": "no-cache",
                    "Pragma": "no-cache"
                },
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function (data) {
                    alert(data.msg);
                    if (data.flag === 1) {

                    }
                }
            });
        }

        function logout() {
            if (confirm("是否确认退出")) {
                let formData = new FormData();
                $.ajax({
                    url: "${pageContext.request.contextPath}/logout",
                    headers: {
                        "Cache-Control": "no-cache",
                        "Pragma": "no-cache"
                    },
                    type: "post",
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    success: function (data) {
                        alert(data.msg);
                        if (data.flag === 1) {
                            window.location.href = "${pageContext.request.contextPath}/login"
                        }
                    }
                });
            }

        }

    </script>
</head>

<body>
<div class="row shadow-sm p-3 mb-5 bg-white rounded">
    <div class="col-2 d-flex justify-content-center align-items-center"
         style="height: 60px;">
        <h2>简易进销存</h2>
    </div>
    <div class="col-10 d-flex justify-content-end align-items-center">
        <h5>
            <c:if test="${sessionScope.u.role==0}">
                管理员
            </c:if> <c:if test="${sessionScope.u.role==1}">
            采购员
        </c:if> <c:if test="${sessionScope.u.role==2}">
            销售员
        </c:if> <c:if test="${sessionScope.u.role==3}">
            供应商
        </c:if><c:if test="${sessionScope.u.role==4}">
            客户
        </c:if>
        </h5>
        <h5>：${sessionScope.u.userName}
            <button id="out" type="button" class="btn btn-light" style="margin-left: 50px" onclick="logout()">退出
            </button>
        </h5>
    </div>
</div>
<div class="row" style="height: 700px;">
    <div class="col-2">
        <div class="border-right"></div>
        <div class="accordion"
             id="accordionExample">
            <c:if test="${sessionScope.u.role==0||sessionScope.u.role==1}">
                <div class="accordion-item">
                    <h2 class="accordion-header"
                        id="headingOne">
                        <button class="accordion-button"
                                type="button"
                                data-bs-toggle="collapse"
                                data-bs-target="#collapseOne"
                                aria-expanded="true"
                                aria-controls="collapseOne">
                            进货管理
                        </button>
                    </h2>
                    <div id="collapseOne"
                         class="accordion-collapse collapse show"
                         aria-labelledby="headingOne"
                         data-bs-parent="#accordionExample">
                        <div class="accordion-body">
                            <a href="${pageContext.request.contextPath}/purchaseTable"
                               target="myiframe"
                               class="list-group-item list-group-item-action active"
                               aria-current="true">
                                进货
                            </a>
                        </div>
                        <c:if test="${sessionScope.u.role==1}">
                        <div class="accordion-body">
                            <a href="${pageContext.request.contextPath}/stockTable"
                               target="myiframe"
                               class="list-group-item list-group-item-action active"
                               aria-current="true">
                                库存
                            </a>
                        </div>
                        </c:if>
                    </div>
                </div>
            </c:if>
            <c:if test="${sessionScope.u.role==0||sessionScope.u.role==2}">
                <div class="accordion-item">
                    <h2 class="accordion-header"
                        id="headingTwo">
                        <button class="accordion-button collapsed"
                                type="button"
                                data-bs-toggle="collapse"
                                data-bs-target="#collapseTwo"
                                aria-expanded="false"
                                aria-controls="collapseTwo">
                            销售管理
                        </button>
                    </h2>
                    <div id="collapseTwo"
                         class="accordion-collapse collapse"
                         aria-labelledby="headingTwo"
                         data-bs-parent="#accordionExample">

                        <div class="accordion-body">
                            <a href="${pageContext.request.contextPath}/saleTable"
                               target="myiframe"
                               class="list-group-item list-group-item-action active"
                               aria-current="true">
                                销售
                            </a>
                        </div>
                        <c:if test="${sessionScope.u.role==1}">
                        <div class="accordion-body">
                            <a href="${pageContext.request.contextPath}/stockTable"
                               target="myiframe"
                               class="list-group-item list-group-item-action active"
                               aria-current="true">
                                库存
                            </a>
                        </div>
                        </c:if>
                    </div>

                </div>
            </c:if>
            <c:if test="${sessionScope.u.role==0}">
            <div class="accordion-item">
                <h2 class="accordion-header"
                    id="headingThree">
                    <button class="accordion-button collapsed"
                            type="button"
                            data-bs-toggle="collapse"
                            data-bs-target="#collapseThree"
                            aria-expanded="false"
                            aria-controls="collapseThree">
                        信息管理
                    </button>
                </h2>
                <div id="collapseThree"
                     class="accordion-collapse collapse"
                     aria-labelledby="headingThree"
                     data-bs-parent="#accordionExample">
                    <div class="accordion-body">
                        <a href="${pageContext.request.contextPath}/goodsTable"
                           target="myiframe"
                           class="list-group-item list-group-item-action active"
                           aria-current="true">
                            商品信息
                        </a>
                    </div>
                    <div class="accordion-body">
                        <a href="${pageContext.request.contextPath}/eployeeTable"
                           target="myiframe"
                           class="list-group-item list-group-item-action active"
                           aria-current="true">
                            员工信息
                        </a>
                    </div>
                    <div class="accordion-body">
                        <a href="${pageContext.request.contextPath}/userTable"
                           target="myiframe"
                           class="list-group-item list-group-item-action active"
                           aria-current="true">
                            客户信息
                        </a>
                    </div>
                </div>
            </div>
            </c:if>
        </div>

    </div>
    <div class="col-10">
        <iframe src="${pageContext.request.contextPath}/getWord" name="myiframe" frameborder="0" width="100%" height="100%">1</iframe>
    </div>

</div>


<!-- 引入Bootstrap JavaScript文件，用于实现一些交互效果 -->
<script src="${pageContext.request.contextPath}/bootstrap-5.3.0-alpha1-dist/js/bootstrap.min.js"></script>
</body>

</html>